from appium import webdriver
import datetime,os,time
#-----------------------------包名相关信息-----------------
desired_caps = {'platformName': 'Android',
                 'deviceName': '127.0.0.1:7555',
                'platformVersion': '8.0',
                'appPackage': 'com.ssf.im',
                'appActivity': 'com.ssf.imkotlin.ui.welcome.WelcomeActivity'
                }
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.implicitly_wait(5)
print('start App')

for i in range(100):
    user = "13"+str(datetime.datetime.now())[-13:].replace(':', '').replace('.', '')
    driver.find_element_by_id("com.ssf.im:id/et_pwd").send_keys(user)
    driver.find_element_by_id("com.ssf.im:id/etMessage").send_keys("0000")
    driver.find_element_by_id("com.ssf.im:id/tvLogin").click()

    #生日和用户名
    driver.find_element_by_id("com.ssf.im:id/tvBirthday").click()
    time.sleep(1)
    driver.find_element_by_id("com.ssf.im:id/btnSubmit").click()
    time.sleep(1)
    driver.find_element_by_name("请输入用户名").send_keys(user[5:0:-1])
    time.sleep(1)

    #上传头像
    driver.find_element_by_id("com.ssf.im:id/ivPortrait").click()
    #相册选择
    driver.find_element_by_id("com.ssf.im:id/tv_select_from_photoes_touxiang").click()
    time.sleep(2)
    os.system(r"D:\working\Aotolt\A_updataPic.exe")
    time.sleep(3)
    driver.find_element_by_id("com.ssf.im:id/tv_sure").click()
    time.sleep(3)
    driver.find_element_by_name("下一步").click()

    driver.find_element_by_id("com.ssf.im:id/tv_ensure").click()
    driver.find_element_by_name("男人本色").click()
    driver.find_element_by_id("com.ssf.im:id/tv_next").click()

    driver.find_element_by_name("Hi，有空吗，聊聊呗").click()
    driver.find_element_by_id("com.ssf.im:id/tv_send").click()
    driver.find_element_by_id("com.ssf.im:id/tv_got_it").click()
    time.sleep(1)
    #我-退出按钮
    driver.find_element_by_id("com.ssf.im:id/tv_title").click()
    driver.find_element_by_xpath('//android.widget.TextView[contains(@text, "我")]').click()
    driver.find_element_by_id("com.ssf.im:id/ll_setting").click()
    driver.find_element_by_id("com.ssf.im:id/btn_logout").click()
    driver.find_element_by_id("com.ssf.im:id/dialog_tv_ensure").click()

